import pprint

from django.utils.deprecation import MiddlewareMixin
from django.http import JsonResponse


class CheckLogin(MiddlewareMixin):

    def process_request(self, request):
        if request.method != "GET" and request.path_info.find("/login/") == -1:
            is_login = request.session.get('account_username', '')
            if not is_login:
                data = {
                    "status": 403,
                    "message": "您的账号或密码错误，请重试，若未注册，请前往注册页面注册"
                }
                pprint.pprint(data)
                return JsonResponse(data=data)
